```{r setup, include=FALSE}
knitr::opts_chunk$set(
  results = 'asis',
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  fig.align = 'center'
)


#Load libraries
library(tidyverse)
library(kableExtra)
library(cowplot)
```


# Introduction
Hi, welcome to my Data School Final Project! I joined CSIRO in 2015 leaving Denmark for this great opportunity to work on agriculture in a country with tight link between growers and scientists.

Before joining Data School my R experience was adopting colleagues’ scripts and running them on my own data - once combating the challenge of how to load data. Experiencing more of the power R has on offer during Data School, I'm now determined to find the time to compose my own R scripts and free myself from excel and untraceable errors. 


# My Project
In our project team we exploit early vigour to breed weed-competitive wheat and proof of concept test the competitiveness caused by high-vigour. Our data comes from field trials and are predominantly phenotype data in the form of scores (1-5), weights or counts. We typically run our trials in several environments, which can be different sites, irrigation regimes or years. We also measure co-factors such as length of plots and weather data. 


## Does weed species matter?
In 2017 and 2018 we tested wheat competitive ability towards different weed species of Australian commercial cultivars and developed high-vigour lines in Condobolin. Because purposely spreading weeds is no option, we use non-wheat crops as weed-surrogates and grow and harvest them in mixtures.  
To experimentally test if the type of weed influences the competitive ability of wheat, we grew 2 commercial varieties and seven of our developed vigorous lines with six different weed-surrogates testing the interaction of wheat genotypes and weed species.
 

```{r include=FALSE}

table.weed <- read_csv("C:/Users/ing06d/Documents/Data school FOCUS/DataSchoolFinalProject/Cathrine Ingvordsen/data/table weeds.csv")

```

```{r mytable, echo=FALSE, out.width='100%'}

knitr::kable(head(table.weed, n = 6), format = "html", caption = "Weed-surrogates") %>% 
  kable_styling("striped")
```


## Preliminary results
The used weed-surrogates decreased wheat yield differently with tall barley (Fb) to be the strongest weed-competitor. The Australian commercial varieties showed greater decrease with competition than without competition (ctrl). The final wheat yield of Australian commercial varieties without competition (ctrl) were considerable higher than the yield of the developed high-vigour lines, however, these were bred for high-vigour with no consideration of yield. 

```{r preparing data, include=FALSE}

GxS <- read_csv("C:/Users/ing06d/Documents/Data school FOCUS/DataSchoolFinalProject/Cathrine Ingvordsen/data/GxS17and18Irr.csv")

GxS %>% 
mutate(Genotype = as.factor(Genotype)) %>% 
mutate(weed = as.factor (weed))

## prep for errorbars

GxS_SE <- 
GxS %>% 
  mutate(yld.SEmin = yld - yld.SE) %>% 
  mutate(yld.SEmax = yld + yld.SE)


# each weeds on each genotype

Mace <- 
  GxS_SE %>% 
  filter(Genotype == "Mace")

Scout <- 
  GxS_SE %>% 
  filter(Genotype == "Scout")

W091106 <- 
  GxS_SE %>% 
  filter(Genotype == "W091106")

W120206 <- 
  GxS_SE %>% 
  filter(Genotype == "W120206")

W320101 <- 
  GxS_SE %>% 
  filter(Genotype == "W320101")

W470201 <- 
  GxS_SE %>% 
  filter(Genotype == "W470201")



W670203 <- 
  GxS_SE %>% 
  filter(Genotype == "W670203")

W670704 <- 
  GxS_SE %>% 
  filter(Genotype == "W670704")

```

```{r making the graphs, echo = FALSE}

plot1 <- 
  Mace %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
            fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("Mace") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot2 <- 
  Scout %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("Scout") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot3 <- 
  W091106 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W091106") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot4 <- 
  W120206 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W120206") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot5 <- 
  W320101 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W320101") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot6 <- 
  W470201 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W470201") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot7 <- 
  W670203 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W670203") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

plot8 <- 
  W670704 %>% 
  ggplot(aes(x = factor(weed, level = c('ctrl', 'Wr', 'Ca', 'Bo', 'Mo', 'Fb', 'Hb')), y = yld)) +
  geom_bar(stat = "identity", position=position_dodge(), 
           fill = c("darkgrey", "lightcyan4", "paleturquoise4", "lightsteelblue3", "lightblue",  "lightskyblue1", "paleturquoise1")) +
  geom_errorbar(aes(ymin = yld.SEmin, ymax = yld.SEmax), width = 0.2) +
  ggtitle("W670704") +
  theme(plot.title = element_text(size = 10)) +
  labs(y="Yield (t/ha)", x=" ", size = rel(1.2)) +
  theme(axis.text.x = element_text(size = rel(1.0))) + 
  ylim(0, 6.05)

```

```{r figure, out.width='100%', fig.align='center', fig.height= 6, fig.width=14, fig.cap="Wheat grain yield of Australian commercial varieties Mace and Scout and developed high-vigour lines W091106, W120206, W320101, W470201, W670203, W670704 grown in Condobolin without competition (ctrl) or in competition with winter ryegrass (Wr), canola (Ca), tall oat (Bo; Bannister oat), short oat (Mo; Mitika oat), tall barley (Fb; Fathom barley) and short barley (Hb; Hindmarsh barley)."}


plot_grid(plot1, plot2, plot3, plot4, plot5, plot6, plot7, plot8,
          nrow = 2,
          ncol = 4,
          labels = "auto", label_size = 10)

```

# My Digital Toolbox

I've filled my digital toolbox with numerous functions of tidyverse. To not manipulate my field scorings made in excel I’ll use full_join to combine the sheets many, many times. I'll use functions from the regular expressions to secure consistency in naming, scorings, measurements and comments. Finally, when getting to the data analysis ggplot will be my go-to for initial data exploration and visualisation for final publications. Regarding ggplot I suspect I'll get across more than what we've learned in Data School.  

# My time went ...
My time went primarily with ggplot for this final project, making already analysed data presentable. Going back and forth from script to final presentation considering e.g. font size was more time consuming than I expected.

# Next steps
Next step is prioritising time for R and keep doing that. In the future I'd get really excited by a database to store field data measurements and photos designed by field scientists. Such data base would free me from my own folder system, which in busy times gets chaotic, and further free up space on my computer.

# My Data School Experience
My Data School has been brilliant. Huge Thanks to Team Kristian, Stephen and Karensa!

I'm now more confident that the time invested in R is paying off and tasks possible with the support of the Data School network. Moving into the habit of using R systemically and frequently has already begun with establishing my freshly sown trials with a R project for each trial. 
The personal impact will initially be investment of time and later when I can reuse my own(!) R scripts save me time.


**Images from a file**

![](resources/img/tidyverse.png){width=100px}![](https://raw.githubusercontent.com/tidyverse/ggplot2/master/man/figures/logo.png){.pull-right width=100px}

